home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / barbu2 / memblock.cpp < prev    next >
C/C++ Source or Header  |  1995-04-27  |  1KB  |  57 lines

  1. ////////////////////////////////////////////////////////////////////////////
  2. // MEMBLOCK implementation
  3. ////////////////////////////////////////////////////////////////////////////
  4. #include "MEMBLOCK.HPP"
  5. #include <mem.h>
  6.  
  7. MEMBLOCK::MEMBLOCK()
  8. {
  9. _len = _space = _maxAdd = 0;
  10. _buf = 0;
  11. }
  12.  
  13. MEMBLOCK::~MEMBLOCK()
  14. {
  15. if(_buf != 0){
  16.     delete _buf;
  17.     _buf = 0;
  18.     }
  19. }
  20.  
  21. short MEMBLOCK::add(const unsigned char Slot[], unsigned long SlotLength)
  22. {
  23. if(_maxAdd < SlotLength)
  24.     _maxAdd = SlotLength;
  25. if(_len + SlotLength <= _space){
  26.     for(unsigned long k = 0; k < SlotLength; k++)
  27.         _buf[k+_len] = Slot[k];
  28.     _len += SlotLength;
  29.     return 1;
  30.     }
  31. if(!addSpace(60000UL))
  32.     return 0;
  33. for(unsigned long k = 0; k < SlotLength; k++)
  34.     _buf[k+_len] = Slot[k];
  35. _len += SlotLength;
  36. return 1;
  37. }
  38.  
  39. unsigned long MEMBLOCK::space() const
  40. {
  41. return _space;
  42. }
  43.  
  44. short MEMBLOCK::addSpace(unsigned long ExtraLength)
  45. {
  46. unsigned long lNew =_len + ExtraLength;
  47. unsigned char huge *  pNew = new huge unsigned char[lNew];
  48. if(pNew == 0)
  49.     return 0;
  50. for(unsigned long k = 0; k < _len; k++)
  51.     pNew[k] = _buf[k];
  52. delete _buf;
  53. _buf = pNew;
  54. _space = lNew;
  55. return 1;
  56. }
  57.